var DataTypes = require("sequelize").DataTypes;
var _lib_book_locations = require("../models/lib_book_locations");
var _lib_book_reviews = require("../models/lib_book_reviews");
var _lib_books = require("../models/lib_books");
var _lib_borrowings = require("../models/lib_borrowings");
var _lib_users = require("../models/lib_users");
const sequelize = require("../config/db")

function initModels(sequelize) {
  var lib_book_locations = _lib_book_locations(sequelize, DataTypes);
  var lib_book_reviews = _lib_book_reviews(sequelize, DataTypes);
  var lib_books = _lib_books(sequelize, DataTypes);
  var lib_borrowings = _lib_borrowings(sequelize, DataTypes);
  var lib_users = _lib_users(sequelize, DataTypes);

  lib_book_locations.belongsTo(lib_books, { as: "book", foreignKey: "book_id"});
  lib_books.hasMany(lib_book_locations, { as: "lib_book_locations", foreignKey: "book_id"});
  lib_book_reviews.belongsTo(lib_books, { as: "book", foreignKey: "book_id"});
  lib_books.hasMany(lib_book_reviews, { as: "lib_book_reviews", foreignKey: "book_id"});
  lib_borrowings.belongsTo(lib_books, { as: "book", foreignKey: "book_id"});
  lib_books.hasMany(lib_borrowings, { as: "lib_borrowings", foreignKey: "book_id"});
  lib_book_reviews.belongsTo(lib_users, { as: "user", foreignKey: "user_id"});
  lib_users.hasMany(lib_book_reviews, { as: "lib_book_reviews", foreignKey: "user_id"});
  lib_borrowings.belongsTo(lib_users, { as: "user", foreignKey: "user_id"});
  lib_users.hasMany(lib_borrowings, { as: "lib_borrowings", foreignKey: "user_id"});

  return {
    lib_book_locations,
    lib_book_reviews,
    lib_books,
    lib_borrowings,
    lib_users,
  };
}
module.exports = initModels(sequelize);
module.exports.initModels = initModels(sequelize);
module.exports.default = initModels(sequelize);
